//https://leetcode.cn/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/

void Swap(int* x, int* y)
{
    int temp = *x;
    *x = *y;
    *y = temp;
}

int* trainingPlan(int* actions, int actionsSize, int* returnSize) {
    *returnSize = actionsSize;
    int* ret = (int*)malloc(sizeof(int) * actionsSize);
    if (ret == NULL)
    {
        perror("malloc fail\n");
        return NULL;
    }

    int left = 0;
    int right = actionsSize - 1;
    while (left <= right)
    {
        if (actions[left] % 2 != 0)
        {
            left++;
            continue;
        }
        if (actions[right] % 2 == 0)
        {
            right--;
            continue;
        }
        if (actions[left] % 2 == 0 && actions[right] % 2 != 0)
        {
            Swap(&actions[left], &actions[right]);
            left++;
            right--;
        }
    }

    memcpy(ret, actions, sizeof(int) * actionsSize);
    return ret;

}